<template>
	<view>
		<textarea v-model="schContent" class="scontent" :maxlength="200" placeholder="请输入总结内容"/>
		<!-- <view class="file-row">
			<view class="title">图片</view>
			<sunui-upimg @change="getImageInfo1" ref="upimg1" ></sunui-upimg>
		</view>
		<view class="file-row">
			<view class="title">PDF</view>
			<l-file ref="lFile" @up-success="onSuccess"></l-file>
			<view class="flex flex-align-center flex-pack-justify" >
			// 动态创建input标签
			<view class="addBox" @tap="onUpload">
				<uni-icons type="cloud-upload" size="50" color="#5C5C5C" class="iconstyle"></uni-icons>
				<view class="uploadtitle">点击上传文件</view>
			</view>
		 
			// 上传的文件列表展示
			<view class="filesBox" v-if="filePdfUrls.length > 0">
				<template v-for="(item,index) in filePdfUrls">
					<view class="fileslist" :key="index">
						<uni-icons type="paperclip" size="20" class="upfileico"></uni-icons>
						<text :key="index" class="upname rf-ellipsis" @click="onOpenDoc(item.url)">{{item.name}}</text>
						<uni-icons type="clear" size="22" class="upclose" @click="delUpFile(item,index)" color="#e54d42"></uni-icons>
					</view> 
				</template>
			</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	import sunUiUpimg from '@/components/sunui-upimg/sunui-upimg.vue'
	import uniIcons from '@/components/uni-icons/uni-icons.vue'

	export default {
		components: { sunUiUpimg, uniIcons },
		data() {
			return {
				schitemId: '',
				schContent: '',
				fileImgUrls: [],
				filePdfUrls: [],
				fileUrls: []
			};
		},
		onLoad(option) {
			this.schitemId = option.pkid
		},
		onNavigationBarButtonTap() {
			
			if (this.schContent.length === 0) {
				this.$u.toast('请输入总结内容');
				return
			}
			this.$u.api.setDone({pkid: this.schitemId}).then(res => {
				let fileList = [...this.fileImgUrls,...this.filePdfUrls]
				for(let i=0;i<fileList.length;i++){
					this.fileUrls.push(fileList[i].pkid)
				}
				
				let _obj = {
					schitemId: this.schitemId,
					schContent: encodeURIComponent(this.schContent),
					fileUrls: this.fileUrls
				}
				this.$u.api.addSummry(_obj).then(res => {
					this.$u.toast('提交成功')
					this.$u.route({type: 'back'})
				}).catch(err => {
					console.error(err)
				})
			}).catch(err => {
				console.error(err)
			})
		},
		methods: {
			/* 预览 */
			onOpenDoc(paths) {
				let url = paths
				/* 下载返回临时路径（退出应用失效） */
				this.$refs.lFile.download(url)
				.then(path=>{
					/* 预览 */
					this.$refs.lFile.open(path);
				});
			},
			/* 上传 */
			onUpload() { 
				// const _userInfo = uni.getStorageSync('USERINFO')
				const _token = uni.getStorageSync(config.Global.cache + '_Token');
				this.$refs.lFile.upload({
					// #ifdef APP-PLUS
					currentWebview: this.$mp.page.$getAppWebview(),
					// #endif
					url: config.Global.BaseUrl + 'mobile/common/file/upload/v2',
					//默认file,上传文件的key
					name: 'file',
					header: {'Authorization': _token},
					fileList:this.filePdfUrls
				});
			},
			onSuccess(res) {
				let _data = JSON.parse(res.data.id).data
				this.filePdfUrls.push(_data); // 上传成功后放进fileList数组用于展示
			},
			delUpFile(data,idx){
				let url =this.schData.filePdfUrls[idx]
				helper.ajax({
					url: 'mobile/schedule/fileDelete',
					method: 'post',
					data: {url},
					success: res => {
						this.schData.filePdfUrls = this.schData.filePdfUrls.filter(item => item.pkid !== data.pkid)
					}
				});
				
			},
			getImageInfo1(e) {
				this.fileImgUrls = []
				for(let i=0;i<e.length;i++){
					this.fileImgUrls.push(e[i])
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scontent {
		box-sizing: border-box;
		padding: 16px;
		width: 100%;
		border-bottom: 1px solid #eee;
	}
	.file-row {
		padding: 16px;
		.title {
			font-size: 18px;
			font-weight: bold;
		}
	}
	.addBox{
		width: 100%;
		height: 100px;
		text-align: center;
		// background: url(../../static/img/upload.png) no-repeat center center;		
		position: relative;
		border: 1px dashed #1890FF;
		margin: 0 auto;
		border-radius: 8px;
		background-color: #FAFAFA;
	}
	.iconstyle {
		display: inline-block;
		margin: 0 auto;
		margin-top: 15px;
		text-align: center;
	}
	.uploadtitle{
		position: absolute;
		bottom: 12rpx;
		left: 0;
		right: 0;
	}
	
	.filesBox{
		margin-top: 28rpx;
	}
	
	.fileslist{
		margin-top: 8px;
	}
	
	.upfileico{
		width: 40rpx;
		height: 40rpx;
		display: inline-block;
		float: left;
		line-height: 40rpx;
	
		margin-right: 2px;
	}
	
	.upname{
		font-size: 26rpx;
		line-height: 40rpx;
		color: #333333;
		width: 80%;
		display: inline-block;
	}
	
	.upclose{
		width: 40rpx;
		height: 40rpx;
		display: inline-block;
		float: right;
	} 
</style>
